<!DOCTYPE html>
<html lang="zh-CN">
<meta charset="utf-8" />
<head>
<title>编辑媒体 <?php echo $this->config->item('title');?>
</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet"	href="<?php echo base_url()?>public/css/bootstrap.min.css">
<link rel="stylesheet"	href="<?php echo base_url()?>public/css/style.css">
<link rel="stylesheet" href="<?php echo base_url()?>public/css/bootstrap-select.min.css">
</head>
<body>
	<script src="<?php echo base_url()?>public/js/jquery-2.0.2.min.js"></script>
	<script src="<?php echo base_url()?>public/js/bootstrap.min.js"></script>
	<script src="<?php echo base_url()?>public/js/bootstrap-confirm.js"></script>
	<script src='<?php echo base_url()?>public/js/bootbox.min.js'></script>
	<script src='<?php echo base_url()?>public/js/jquery.form.js'></script>
	<script src='<?php echo base_url()?>public/js/ssi_common.js'></script>
	<script type="text/javascript"	src="http://api.map.baidu.com/api?v=1.5&ak=C17fc65597a3939334b09677dcba39fd"></script>
	<script type="text/javascript"	src="http://api.map.baidu.com/library/DistanceTool/1.2/src/DistanceTool_min.js"></script>
	<script src='<?php echo base_url()?>public/js/bootstrap-select.min.js'></script>
	<script type="text/javascript">
	function buildMarker(map, x, y) {
		var newmarker = new BMap.Marker(new BMap.Point(x, y));
		map.addOverlay(newmarker);
		newmarker.enableDragging(true);
		newmarker.enableMassClear();
		return newmarker;
	}
	function updatePoint(point) {
		$("#longitude").val(point.lng);
		$("#latitude").val(point.lat);
	}
	var map;
	$().ready(function() {
		map = new BMap.Map("map");
		map.enableScrollWheelZoom();//允许滚轮缩放
		map.addControl(new BMap.NavigationControl());//加载放大缩小插件
		var local = new BMap.LocalSearch(map, {renderOptions:{map: map}});
		var myDis = new BMapLib.DistanceTool(map);
		 $('#searchbtn').click(function() {
		  var key = $('#searchtext').val();
		  local.searchInBounds(key, map.getBounds());
		 });
		 $('#disttoolbtn').click(function() {
		  myDis.open();//myDis.close();  //关闭鼠标测距大
		 });
		map.addEventListener("click",function(e){
			//新增地图标注
			map.clearOverlays();
			var marker = buildMarker(map, e.point.lng, e.point.lat);
			updatePoint(e.point);
			marker.addEventListener("dragend", function(e2) {
			updatePoint(e2.point);
			});
		});
		var longitude = $("#longitude").val();
		var latitude = $("#latitude").val();
		if (longitude) {
			 map.centerAndZoom(new BMap.Point(longitude, latitude), 13);
			 marker = buildMarker(map, longitude, latitude);
		} else {
			 map.centerAndZoom("武汉"); 
		}

		 
	});

		
	jQuery(function($) {

		var change_sm =false;


		$("#change_sketch_map").click(function(){
			if (change_sm==false) {
				change_sm =true;
				$(this).text("取消修改");
				$(".sketch_map").show();
			}else{
				change_sm =false;
				$(this).text("变更示意图");
				file = $("#sketch_map");  
				file.after(file.clone());   
				file.remove();  
				$(".sketch_map").hide();
			}
		 
		});
		
		$('.selectpicker1').selectpicker({});
		$('.selectpicker').selectpicker();
		$('.led_selectpicker').selectpicker();
		$('#main_from').ajaxForm({
			dataType:  'json',
			beforeSubmit:  showRequest,
			success:   processJson
		});
		function showRequest(formData, jqForm, options) {
		}
	
		function processJson(data) {
			if (data.result==false) {
				bootbox.alert(data.message, function() {
				});
				$('button[type="button"]').removeClass('disabled');
			}else{
				window.location.href=data.redirect_url;
			}
		}

		$("#media_type").change(function(){
			if ($(this).val()=="airport") {
				$("#airport").show();
				$("#airport_led").hide();
				$("#airport_led").find("input").val("");
				$("#airport_led").find("select").val("");
				$('.led_selectpicker').selectpicker('refresh');
			}else{
				$("#airport_led").show();
				$("#airport").hide();
				$("#airport").find("input").val("");
				$("#airport").find("select").val("");
			}
		});
	});
	</script>
	<div role="navigation" class="navbar navbar-inverse navbar-fixed-top">
		<div class="container">
			<div class="navbar-header">
				<a class="navbar-brand">SSI后台管理系统</a>
			</div>
			<div class="collapse navbar-collapse navbar-right">
				<ul class="nav navbar-nav">
					<li><a href="<?php echo base_url()?>" class="navbar-link">首页</a></li>
					<li><a
						href="<?php echo base_url()."index.php/common_login_user_set"?>"
						class="navbar-link">超级管理员</a></li>
					<li><a
						href="<?php echo base_url()?>index.php/common_login_manage/logout"
						class="navbar-link">退出</a></li>
				</ul>
			</div>
		</div>
	</div>
	<div class="container">
		<div class="row">
			<div class="col-xs-3">
				<?php echo $user_menu?>
			</div>
			<div class="col-md-9">
				<div class="panel panel-default">
					<div class="panel-heading">编辑媒体</div>
					<div class="panel-body">
						<form method="post" enctype="multipart/form-data" id="main_from"	action="<?php echo base_url()."index.php"?>/media_media_manage/update_media_draft" class="form-horizontal">
							<div  class="form-group">
								<label for="" class="control-label col-sm-3">媒体类型</label>
								<div class="col-sm-5">
									<select name="media_type" id="media_type"  class="form-control">
										<option value="airport" <?php echo $media_draft_info['media_type'] =="airport"?"selected=\"selected\"":"";?> >机场常规大牌</option>
										<option value="airport_led"  <?php echo $media_draft_info['media_type'] =="airport_led"?"selected=\"selected\"":"";?>>机场LED大屛</option>
									</select>
								</div>
							</div>
							<div id="Parents" class="form-group">
								<label for="parent1" class="control-label col-sm-3">所属地区</label>
								<div id="parents" class="col-sm-5">
									<select id="parent1" name="province"
										onchange="onParent1Changed()" class="form-control">
										<option	value="0">无</option>
										<?php if ($top_regions!=null) {
												foreach ($top_regions as $region){	?>
										<option value="<?php echo $region['region_id']?>" <?php echo $region['region_id']==$media_draft_info['province']?'selected="selected"':''?>   ><?php echo $region['region_name']?></option>
										<?php 
											}
										}?>
									</select>
									<?php if ($second_regions!=null) {?>
									<select id="parent2" name="city"	onchange="onParent2Changed()" class="form-control">
										<option	value="0">无</option>
										<?php foreach ($second_regions as $sec_region){	?>
										<option value="<?php echo $sec_region['region_id']?>" <?php echo $sec_region['region_id']==$media_draft_info['city']?'selected="selected"':''?>   ><?php echo $sec_region['region_name']?></option>
										<?php } ?>
									</select>
									<?php }?>
									<?php if ($last_regions!=null) {?>
									<select id="parent3" name="region"	onchange="onParent3Changed()" class="form-control">
										<option	value="0">无</option>
										<?php foreach ($last_regions as $last_region){
												$region_type ="";
											if ($last_region['region_type']=="10") {
												$region_type ="(中心城区)";
											}if($last_region['region_type']=="20"){
								 			   $region_type="(周边城区)";
								 			}
								 			if($last_region['region_type']=="30"){
								 				$region_type="(下属县市)";
								 			}
								 			if($last_region['region_type']=="40"){
								 			   $region_type="(下属镇区)";
								 			}	?>
										<option value="<?php echo $last_region['region_id']?>" <?php echo $last_region['region_id']==$media_draft_info['region']?'selected="selected"':''?>   ><?php echo $last_region['region_name'].$region_type?></option>
										<?php } ?>
									</select>
									<?php }?>
								</div>
								<span class='help-block'>必选</span>
							</div>
							<div  class="form-group">
								<label for="location" class="control-label col-sm-3">媒体位置</label>
								<div class="col-sm-5">
									<input id="location" type="text" name="location" value="<?php echo $media_draft_info['location']?>" class="form-control">
								</div>
								<span class='help-block'>必填</span>
							</div>
							<input id="latitude" name="latitude" value="<?php echo $media_draft_info['latitude']?>" type="hidden">
							<input id="longitude" name="longitude" value="<?php echo $media_draft_info['longitude']?>" type="hidden">
							<div class="form-group">
								<div id="map" style="height: 400px;"
									class="col-sm-10 col-sm-offset-1"></div>
									<div class="col-sm-6 col-sm-offset-2"><div class="input-group input-group-sm"><span class="input-group-addon">参照物</span><input id="searchtext" type="text" class="form-control"><a id="searchbtn" class="input-group-addon"><span class="glyphicon glyphicon-search"></span></a></div></div><div class="col-sm-3"><a id="disttoolbtn" class="btn btn-default btn-sm">测距</a></div>
							
							</div>
							<br>
							<div  class="form-group vendor">
								<label for="vendor" class="control-label col-sm-3 ">供应商</label>
								<div class="col-sm-5" >
									<select id="vendor" name="vendor" class='span5 region_select selectpicker form-control' data-live-search='true'>
										<?php if ($vendor_list!=null) {
											foreach ($vendor_list as $vendor){?>
											<option value="<?php echo $vendor['vendor_id']?>" <?php echo $vendor['vendor_id']==$media_draft_info['vendor']?'selected="selected"':''?> ><?php echo $vendor['company_name']?></option>	
										<?php }
										}?>
									</select>
								</div>
							</div>
							<div  class="form-group">
								<label  class="control-label col-sm-3">所属机场</label>
								<div class="col-sm-5">
									<select id="airport_id"  name ="airport_id" data-live-search='true'  class="selectpicker1 form-control">
										<option value="">请选择</option>
										<?php if ($airport_list!=null) {
											foreach ($airport_list as $airport){?>
										<option value="<?php echo $airport['airport_id']?>" <?php echo $airport['airport_id']==$media_draft_info['airport_id']?'selected="selected"':''?>><?php echo $airport['airport_name']?></option>
										<?php }
										}?>
									</select>
								</div>
								<span class='help-block'>必填</span>
							</div>
							<div  class="form-group">
								<label for="media_type_id" class="control-label col-sm-3">媒体形式</label>
								<div class="col-sm-5">
									<select id="media_type_id" name="media_type_id" class="form-control">
										<option value="0">无</option>
										<?php 
										if ($media_type_list!=null) {
											foreach ($media_type_list as $mt){
											?>
										<option value="<?php echo $mt['media_type_id']?>" <?php echo $mt['media_type_id']==$media_draft_info['media_type_id']?'selected="selected"':''?>><?php echo $mt['media_type_name']?></option>
										<?php }
										}?>
									</select>
								</div>
							</div>
							<div  class="form-group">
								<label for="agreement" class="control-label col-sm-3">是否有手续</label>
								<div class="col-sm-5">
									<select id="agreement" name="agreement" class="form-control">
										<option value="0" <?php echo $media_draft_info['agreement']==0?"selected=\"selected\"":"";?> >暂无信息</option>
										<option value="10" <?php echo $media_draft_info['agreement']==10?"selected=\"selected\"":"";?>>政府批文</option>
										<option value="20" <?php echo $media_draft_info['agreement']==20?"selected=\"selected\"":"";?>>场租协议</option>
										<option value="30" <?php echo $media_draft_info['agreement']==30?"selected=\"selected\"":"";?>>采购合同</option>
									</select>
								</div>
							</div>
							<div  class="form-group">
								<label for="specification_width" class="control-label col-sm-3">媒体宽</label>
								<div class="col-sm-5">
									<input id="specification_width" type="text" value="<?php echo $media_draft_info['specification_width']?>" name="specification_width" class="form-control">
								</div>
								<span class='help-block'>米</span>
							</div>
							<div  class="form-group">
								<label for="specification_height" class="control-label col-sm-3">媒体高</label>
								<div class="col-sm-5"> 
									<input id="specification_height" type="text" value="<?php echo $media_draft_info['specification_height']?>" name="specification_height" class="form-control">
								</div>
								<span class='help-block'>米</span>
							</div>
							<div  class="form-group">
								<label for="media_area" class="control-label col-sm-3">媒体面积</label>
								<div class="col-sm-5">
									<select id="media_area" name="media_area" class="form-control">
									<?php 
										if ($media_area_list!=null) {
											foreach ($media_area_list as $media_area){
											?>
										<option value="<?php echo $media_area['media_area_id']?>" <?php echo $media_area['media_area_id']==$media_draft_info['media_area']?'selected="selected"':''?>><?php echo $media_area['media_area_name']?></option>
										<?php }
										}?>
									</select>
								</div>
							</div>
							<div  class="form-group">
								<label for="reference_price" class="control-label col-sm-3">交易参考价</label>
								<div class="col-sm-5">
									<input id="reference_price" type="text"  value="<?php echo $media_draft_info['reference_price']?>" name="reference_price" class="form-control">
								</div>
							</div>
							<div  class="form-group">
								<label for="price_remark" class="control-label col-sm-3">价格备注</label>
								<div class="col-sm-5">
									<input id="price_remark" type="text" name="price_remark" value="<?php echo $media_draft_info['price_remark']?>" class="form-control">
								</div>
							</div>
							<div id="airport" style="display: <?php echo $media_draft_info['media_type']=="airport"?"block":"none";?>">
								<div  class="form-group">
									<label for="crafts" class="control-label col-sm-3">制作工艺</label>
									<div class="col-sm-5">
										<select id="crafts" name="crafts" class="form-control">
											<option value="0">无</option>
											<?php 
											if ($crafts_list!=null) {
												foreach ($crafts_list as $crafts){
												?>
											<option value="<?php echo $crafts['crafts_id']?>" <?php echo  $crafts['crafts_id']==$media_draft_info['crafts']?'selected="selected"':''?>><?php echo $crafts['crafts_name']?></option>
											<?php }
											}?>
										</select>
									</div>
								</div>
								<div  class="form-group">
									<label for="corner_case" class="control-label col-sm-3">转角情况</label>
									<div class="col-sm-5">
										<select id="corner_case" name="corner_case" class="form-control">
											<option value="0">无</option>
											<?php 
											if ($corner_case_list!=null) {
												foreach ($corner_case_list as $corner_case){
												?>
											<option value="<?php echo $corner_case['corner_case_id']?>" <?php echo $corner_case['corner_case_id']==$media_draft_info['corner_case']?'selected="selected"':''?>><?php echo $corner_case['corner_case_name']?></option>
											<?php }
											}?>
										</select>
									</div>
								</div>
								<div  class="form-group">
									<label for="illumination" class="control-label col-sm-3">照明情况</label>
									<div class="col-sm-5">
										<select id="illumination" name="illumination" class="form-control">
											<option value="1" <?php echo $media_draft_info['illumination']==1?'selected="selected"':''?>>有</option>
											<option value="0" <?php echo $media_draft_info['illumination']==0?'selected="selected"':''?>>无</option>
										</select>
									</div>
								</div>
								<div  class="form-group">
									<label for="flow" class="control-label col-sm-3">人车流量</label>
									<div class="col-sm-5">
										<select id="flow" name="flow" class="form-control">
											<option value="10" <?php echo $media_draft_info['flow']==10?'selected="selected"':''?>>极大</option>
											<option value="20" <?php echo $media_draft_info['flow']==20?'selected="selected"':''?>>较大</option>
											<option value="30" <?php echo $media_draft_info['flow']==30?'selected="selected"':''?>>一般</option>
											<option value="40" <?php echo $media_draft_info['flow']==40?'selected="selected"':''?>>较小</option>
										</select>
									</div>
								</div>
							</div>
							
							<div id="airport_led" style="display: <?php echo $media_draft_info['media_type']=="airport_led"?"block":"none";?>">
								<div  class="form-group">
									<label for="play_time" class="control-label col-sm-3">开屏时间</label>
									<div class="col-sm-5">
										<input id="play_time" type="text" name="play_time" value="<?php echo $media_draft_info['play_time']?>" class="form-control">
									</div>
								</div>
								<div  class="form-group">
									<label for="play_time_remark" class="control-label col-sm-3">开屏时间备注</label>
									<div class="col-sm-5">
										<input id="play_time_remark" type="text" value="<?php echo $media_draft_info['play_time_remark']?>" name="play_time_remark" class="form-control">
									</div>
								</div>
								<div  class="form-group">
									<label for="play_format" class="control-label col-sm-3">播放格式</label>
									<div class="col-sm-5">
										<select id="play_format" name ="play_format[]" class="led_selectpicker" multiple="multiple">
											<option value="all" <?php echo stristr($media_draft_info['play_format'], "all")?"selected=\"selected\"":""?> >不限</option>
											<option value="avi" <?php echo stristr($media_draft_info['play_format'], "avi")?"selected=\"selected\"":""?>>AVI</option>
											<option value="wmv" <?php echo stristr($media_draft_info['play_format'], "wmv")?"selected=\"selected\"":""?>>WMV</option>
											<option value="mpeg" <?php echo stristr($media_draft_info['play_format'], "mpeg")?"selected=\"selected\"":""?>>MPEG</option>
											<option value="mov" <?php echo stristr($media_draft_info['play_format'], "mov")?"selected=\"selected\"":""?>>MOV</option>
											<option value="jpg" <?php echo stristr($media_draft_info['play_format'], "jpg")?"selected=\"selected\"":""?>>JPG</option>
										</select>
									</div>
								</div>
								<div  class="form-group">
									<label for="resolution" class="control-label col-sm-3">分辨率</label>
									<div class="col-sm-5">
										<select id="resolution" name ="resolution" class="led_selectpicker">
											<?php if ($this->config->item("resolutions")) {
												$resolutions =$this->config->item("resolutions");
												foreach ($resolutions as $resolution){?>
												<option value="<?php echo $resolution?>" <?php echo  $resolution==$media_draft_info['resolution']?"selected=\"selected\"":"";?> ><?php echo $resolution?></option>	
											<?php }
											}?>
										</select>
									</div>
								</div>
								<div  class="form-group">
									<label for="play_frequency" class="control-label col-sm-3">播放频次</label>
									<div class="col-sm-5">
										<input id="play_frequency" type="text" value="<?php echo $media_draft_info['play_frequency']?>"  name="play_frequency" class="form-control">
									</div>
								</div>
								<div  class="form-group">
									<label for="play_frequency_remark" class="control-label col-sm-3">播放频次备注</label>
									<div class="col-sm-5">
										<input id="play_frequency_remark" type="text" value="<?php echo $media_draft_info['play_frequency_remark']?>" name="play_frequency_remark" class="form-control">
									</div>
								</div>
							</div>
							
							<div class="form-group">
								<label for="explanation" class="control-label col-sm-3">审核说明(可选)</label>
								<div class="col-sm-5">
									<input id="explanation" type="text" name="explanation"	class="form-control">
									
									<input type="hidden" name ="media_draft_id" value="<?php echo $media_draft_info['media_draft_id']?>">
									<input type="hidden" name ="sketch_map" value="<?php echo $media_draft_info['sketch_map']?>">
								</div>
								<p class="help-block">供审核人员查看</p>
							</div>
							<div class="form-group">
								<div class="col-sm-offset-3 col-sm-10">
									<button type="button"
										onclick='from_check_login($("#main_from"),"<?php echo base_url()?>")'
										class="btn btn-primary">编辑</button>
									<a href="javascript:void(0)" onclick="history.back()">返回</a>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
	<script>
	function onParent1Changed(){
 		var parent1 = $("#parent1");
 		var parent2 = $("#parent2");
 		parent2.remove();
 		var parent3 = $("#parent3");
 		parent3.remove();
 		clear_region_select();
 		var index = $("#parent1").get(0).selectedIndex;
 		if (index == 0) {
  			return;
 		}
 		var province_name=$("#parent1").find("option:selected").text();
 		if (province_name!="北京"&&province_name!="上海"&&province_name!="天津"&&province_name!="重庆") {
 			$("#location").val($("#parent1").find("option:selected").text());
		}else{
			$("#location").val("");
		}
		
 		map.setCenter($("#parent1").find("option:selected").text());
 		map.setZoom(9);
 		var parentid = parent1.val();
 		$.getJSON(
 		 	"<?php echo base_url()."index.php/sys_region_manage/get_regions"?>", 
 		 	{ region_id: parentid }, 
 		 	function(json){
				if (json.length == 0) {
		   		return;
		 	}
  			$("#parents").append("<select class='span5 form-control' id='parent2' name='city' onchange='onParent2Changed()'></select>");
  			var parent2 = $("#parent2");
 			parent2.append("<option value='0'>无</option>");
  			for(var i = 0, len = json.length; i<len; ++i){
   				var region = json[i];
   				parent2.append("<option value=" + region.region_id + ">" + region.region_name + "</option>");
  			}
 		});
 		$("#vendor").html("");
 		var region = $("#parent1").val();
 		$.getJSON(
 		 	"<?php echo base_url()."index.php/ven_vendor_manage/get_vendors"?>", 
 		 	{ region: region }, 
 		 	function(json){
				if (json.length == 0) {
		   		return;
		 	}
			
  			for(var i = 0, len = json.length; i<len; ++i){
   				var vendor = json[i];
   				$("#vendor").append("<option value=" + vendor.vendor_id + ">" + vendor.company_name + "</option>");
  			}

  			$('.selectpicker').selectpicker('refresh');
 		});
 	
	}
	function onParent2Changed(){
 		var parent2 = $("#parent2");
 		var parent3 = $("#parent3");
 		parent3.remove();
 		var index = $("#parent2").get(0).selectedIndex;
 		map.setCenter($("#parent2").find("option:selected").text());
 		map.setZoom(13);
 		if (index == 0) {
  			return;
 		}
 		var province_name=$("#parent1").find("option:selected").text();
 		if (province_name!="北京"&&province_name!="上海"&&province_name!="天津"&&province_name!="重庆") {
 			$("#location").val(province_name+$("#parent2").find("option:selected").text());
		}else{
			$("#location").val($("#parent2").find("option:selected").text());
		}

		clear_region_select();
 		var parentid = parent2.val();
 		$.getJSON(
 		 	"<?php echo base_url()."index.php/sys_region_manage/get_regions"?>",
 		 	{ region_id: parentid}, 
 		 	function(json){
	  		if (json.length == 0) {
	   			return;
	  		}
	 		$("#parents").append("<select class='span5   form-control' id='parent3' onchange='onParent3Changed()' name='region'></select>");
	  		var parent3 = $("#parent3");
	 		parent3.append("<option value='0'>无</option>");
	 		for(var i = 0, len = json.length; i<len; ++i){
	 		   var region = json[i];
	 		   region_type="";
	 		   if(region.region_type=="10"){
	 			   region_type="(中心城区)";
	 			}
	 			if(region.region_type=="20"){
	 			   region_type="(周边城区)";
	 			}
	 			if(region.region_type=="30"){
	 				region_type="(下属县市)";
	 			}
	 			if(region.region_type=="40"){
	 			   region_type="(下属镇区)";
	 			}
	 		   parent3.append("<option value=" + region.region_id + ">" + region.region_name+region_type + "</option>");
	 		  }
	 		 
	 	});
	}
	function onParent3Changed(){
		clear_region_select();
 		var index = $("#parent3").get(0).selectedIndex;
 		if (index == 0) {
  			return;
 		}
 		var str =$("#parent3").find("option:selected").text();
 		var newStr=str.replace(/\([^\)]*\)/g,"");
 		
 		map.centerAndZoom($('#parent2 option:selected').text()+newStr,13);
 		
 		var province_name=$("#parent1").find("option:selected").text();
 		if (province_name!="北京"&&province_name!="上海"&&province_name!="天津"&&province_name!="重庆") {
 			$("#location").val(province_name+$("#parent2").find("option:selected").text()+newStr);
		}else{
			$("#location").val($("#parent2").find("option:selected").text()+newStr);
		}
	}

	function clear_region_select(){
		
		$('.selectpicker').selectpicker('refresh');
	}


	function remove_pic(class_name){
		$("."+class_name).remove();
	}
	</script>
<div  class="back-to" id="toolBackTop">
	<a title="返回顶部" onclick="window.scrollTo(0,0);return false;" href="#top" class="back-top">
	返回顶部</a>
	<a title="返回底部" onclick="window.scrollTo(0,document.body.scrollHeight);return false;" href="#bottom" class="back-bottom">
	返回底部</a>
</div>
</body>
</html>
